package com.bxd.baodan.fragment;

import android.os.Bundle;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.bxd.baodan.R;
import com.bxd.baodan.util.StringUtil;
import com.bxd.baodan.widget.MyTextWatcher;

/**
 *
 */

public class FamilyIncomeFragment extends BaseStepFragment  {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.step_6_home_salery, null);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        //title.setText(roleText +"的家庭收支" );


        String[] aa = {getDesignStep().family_annual_income,
                getDesignStep().family_month_spending,
                getDesignStep().family_month_alimony,
                getDesignStep().family_loan,

        };


        EditText[] et = {
                getFamilyAnnualIncome(),
        getFamilyMonthSpending(),
        getFamilyMonthAlimony(),
        getFamilyLoan()
        };

        for (int i = 0; i < aa.length; i++) {
            if (!StringUtil.isEmpty(aa[i])) {
                et[i].setText(aa[i]);
            }
        }

        View[] ly ={view.findViewById(R.id.spending_ly),view.findViewById(R.id.alimony_ly),view.findViewById(R.id.loan_ly),};

       String age = getDesignStep().age;
        if (!StringUtil.isEmpty(age)) {
            int age_ = Integer.parseInt(age);


            if (age_ < 18) {
                ly[0].setVisibility(View.GONE);
                ly[1].setVisibility(View.GONE);
                ly[2].setVisibility(View.GONE);
            } else {
                ly[0].setVisibility(View.VISIBLE);
                ly[1].setVisibility(View.VISIBLE);
                ly[2].setVisibility(View.VISIBLE);

            }
        }




        getFamilyAnnualIncome().addTextChangedListener(new MyTextWatcher() {


            @Override
            public void afterTextChanged(Editable s) {
            getDesignStep().family_annual_income = getFamilyAnnualIncome().getText().toString().trim();
            }
        });
        getFamilyMonthSpending().addTextChangedListener(new MyTextWatcher() {


            @Override
            public void afterTextChanged(Editable s) {
                getDesignStep().family_month_spending = getFamilyMonthSpending().getText().toString().trim();

            }
        });
        getFamilyMonthAlimony().addTextChangedListener(new MyTextWatcher() {


            @Override
            public void afterTextChanged(Editable s) {
                getDesignStep().family_month_alimony = getFamilyMonthAlimony().getText().toString().trim();

            }
        });
        getFamilyLoan().addTextChangedListener(new MyTextWatcher() {

            @Override
            public void afterTextChanged(Editable s) {
                getDesignStep().family_loan = getFamilyLoan().getText().toString().trim();

            }
        });

    }

    private EditText getFamilyAnnualIncome(){
        return (EditText) getView().findViewById(R.id.family_annual_income);
    }

    private EditText getFamilyMonthSpending(){
        return (EditText) getView().findViewById(R.id.family_month_spending);
    }

    private EditText getFamilyMonthAlimony(){
        return (EditText) getView().findViewById(R.id.family_month_alimony);
    }

    private EditText getFamilyLoan(){
        return (EditText) getView().findViewById(R.id.family_loan);
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

}
